<template>
    <div class="submit-page">
        <!-- 顶部搜索栏 -->
        <search-sub :isShowCart="false"></search-sub>
        <div class="main" v-loading="loadingPage">
            <div class="wrap" v-if="showPage">
                <!-- 商品信息 -->
                <order-detail :goodsList="orderDetail.orderSupplyGoods" :mapData="mapData" :pageType="2" :totalNum="orderDetail.pick_nums"
                              :totalPrice="orderDetail.total_price" :orderTime="orderDetail.create_time" :orderNumber='orderDetail.order_no'
                              :orderStatus="orderDetail.status" :driver="orderDetail.driver"></order-detail>

            </div>
        </div>
    </div>
</template>

<script>
import SearchSub from "@/components/SearchSub.vue";
import OrderDetail from "@/components/OrderDetail";
import {
    supplyOrderDetail
} from '../../api/order'
import NoData from '@/components/NoData.vue';
export default {
    components: {
        SearchSub,
        OrderDetail,
        NoData,
    },
    data() {
        return {
            loadingPage: true,
            showPage: false,
            supplyOrderId: '',
            orderDetail: {},
            supplyOrderList: [],
            orderType: '',
            mapData: {
                markers: [],
                city: '',
            },

        };
    },
    created() {
        this.supplyOrderId = this.$route.params.id;
        this.getOrderDetail();
    },
    methods: {
        getOrderDetail() {
            const that = this;
            let mapData = that.mapData;
            supplyOrderDetail({
                supply_order_id: that.supplyOrderId
            }).then(res => {
                that.loadingPage = false;
                that.showPage = true;
                if (res.code == 0) {
                    if (res.data.status == 20) {
                        const userAddress = {
                            id: 1,
                            lng: res.data.address.lng,
                            lat: res.data.address.lat,
                            label: res.data.address.detail
                        }
                        const supplyAddress = {
                            id: 3,
                            lng: res.data.supplyAddress.lng,
                            lat: res.data.supplyAddress.lat,
                            label: res.data.supplyAddress.detail
                        }
                        const centerAddress = {
                            id: 2,
                            lng: (parseFloat(userAddress.lng) + parseFloat(supplyAddress.lng)) / 2,
                            lat: (parseFloat(userAddress.lat) + parseFloat(supplyAddress.lat)) / 2,
                            label: '司机位置'
                        }

                        that.mapData = {
                            markers: [userAddress, centerAddress, supplyAddress],
                            city: res.data.address.city_name,
                        };
                    }
                    res.data.total_price = that.sum(res.data.orderSupplyGoods);
                    that.orderDetail = res.data;
                }
            })
        },
        sum(arr) {
            var s = 0;
            for (var i = arr.length - 1; i >= 0; i--) {
                s += parseFloat(arr[i].order_goods_item.total_price);
            }
            return s.toFixed(2);
        }
    },
};
</script>
<style lang="scss" scoped>
::v-deep .el-loading-mask {
    height: calc(100vh - 156px) !important;
}
.main {
    width: 100%;
    padding-bottom: 50px;
    font-size: 14px;
}

.wrap {
    // width: 1180px;
    box-sizing: border-box;
    margin: auto;
    background: #fff;
    border-radius: 12px;
    margin-top: 20px;

    h1 {
        font-size: 16px;
    }
}

.address-wrap {
    h1 {
        font-size: 16px;
        font-weight: bold;
    }
    .address-con {
        width: 461px;
        height: 160px;
        background: url(~@/assets/img/address-bg.png) no-repeat;
        background-size: 100% 100%;
        padding: 0 16px;
        box-sizing: border-box;
        box-shadow: 0px 3px 6px 1px rgba(0, 0, 0, 0.16);
        border-radius: 4px 4px 4px 4px;
        border: 0px solid #707070;
        margin-bottom: 18px;
        margin-top: 25px;
    }

    h2 {
        padding: 12px 0 10px;
        font-size: 14px;
        font-weight: bold;
        border-bottom: 1px solid #e1e1e1;
    }

    p {
        color: #8f8f8f;
        padding-top: 6px;
    }

    span {
        font-size: 16px;
        color: #ff4401;
        padding-top: 20px;
        display: flex;
    }
}

.submit-btn-wrap {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 30px;

    .back-cart {
        color: #5b84d6;
        margin-right: 40px;

        span {
            padding-left: 5px;
        }
    }

    .submit-order {
        width: 130px;
        height: 44px;
        background: #30b30e;
        border-radius: 22px;
        color: #fff;
    }
}
</style>